/**
 * 处理器
 */
import {ApprovalActionEnum} from "../../../constant/ApprovalActionEnum";
import StatusApprove from "./StatusApprove";
import ExecuteApprove from "./ExecuteApprove";
import DuplicateApprove from "./DuplicateApprove";
import VerdictApprove from "./VerdictApprove";


export default class Approve {

    private readonly node: NODE.ApprovalNode;
    private statusApprove: StatusApprove;
    private executeApprove: ExecuteApprove;
    private duplicateApprove: DuplicateApprove;
    private verdictApprove: VerdictApprove;

    protected constructor(node:NODE.ApprovalNode) {
        this.node = node;
        this.statusApprove = new StatusApprove(node);
        this.executeApprove = new ExecuteApprove();
        this.duplicateApprove = new DuplicateApprove();
        this.verdictApprove = new VerdictApprove(node);
    }

    // 根据节点数据类型,选择相应的执行器
    approve(){

        const {nodeType} = this.node;

        switch (nodeType) {
            case ApprovalActionEnum.STATUS:
                this.statusApprove.processMethod()
                break;
            case ApprovalActionEnum.EXECUTE:
                this.executeApprove.processMethod(this.node)
                break;
            case ApprovalActionEnum.DUPLICATE:
                this.duplicateApprove.processMethod(this.node)
                break;
            case ApprovalActionEnum.VERDICT:
                this.verdictApprove.processMethod();
                break;
            default:
                break;
        }
    }
}
